package dao;

import java.util.List;

import model.PowerGroup;
import model.PowerNodes;

import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Component;

@Component
public class PowerDao extends BaseDao {
	public boolean power_check(String action, String method, int powergroup_id)
	{
		Session s = session();
		Criteria cri1 = s.createCriteria(PowerNodes.class);
		Criteria cri2 = s.createCriteria(PowerGroup.class);
		cri1.add(Restrictions.eq("action", action));
		cri1.add(Restrictions.eq("method", method));
		cri2.add(Restrictions.eq("powergroup_id", powergroup_id));
		List<PowerNodes> objs1 = cri1.list();
		List<PowerGroup> objs2 = cri2.list();
		if(objs1.size() > 0)
		{
			if(objs1.get(0).getPowergroup().contains(objs2.get(0)))
			{
				return true;
			}else{
				return false;
			}
		}else{
			return true;
		}
	}
}
